var jName = getCookie('Jname');
//我的权限数组
var arrayTitle = new Array; 
var id='';
var currentPage = 1;

findMyCatalogue();

	$(document).ready(function() {
		init('',currentPage);
	});

	function init(title,pageNo) {
		$("#thislist").html("");
		$.ajax({
			url: urlcore + "/api/classify/findList?current="+ pageNo +"&title="+title,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {

				if(data.success == true) {
					$.each(data.data.records, function(i, n) {
						var id = n.id;
						var thislist = "";
						var name = n.name;
						var inital_price = n.initalPrice;
						var pic_url = n.picUrl;
						var imgStr1 = '';
						if(pic_url != null && pic_url != '') {
						var imgarr = pic_url.split("***");
						$.each(imgarr, function(index, value) {
					 	imgStr1="<img style=\"padding: 5px 5px 5px 5px;\" width=\"45px\" height=\"45px\" src=" + urlcore+value + ">" 
							});
						}
						
					thislist +=
							'<tr class="footable-even" style="display: table-row;">' +
							'<td class="footable-visible">' + id + '</td>' +
							'<td class="footable-visible">' + name + '</td>' +
							'<td class="footable-visible">'+ imgStr1 +'</td>' +
							'<td class="footable-visible">' + inital_price + '</td>' +
							'<td class="footable-visible footable-last-column">' +  
							'<a  hidden="hidden" class="" name="修改" href="classify_update.html?id=' + id + '"> 修改</a>&nbsp;&nbsp;'+
							'<a  hidden="hidden" class="" name="删除" href="javascript:;" onclick="deleteeach(' + n.id + ')"> 删除</a>' + '</td>' +'</tr>';
						$('#thislist').append(thislist);
						$('#thiscount').html(data.data.records.total);
					});
					$("#pager").pager({
	                    pagenumber: pageNo,
	                    pagecount: data.data.pages,
	                    totalcount: data.data.total,
	                    buttonClickCallback: PageClick
	                });
					$.each(arrayTitle, function(i,k) {
						$('a[name="'+k+'"]').attr("hidden",false).attr("class","btn btn-primary btn-xs");
						$('a[data="'+k+'"]').attr("class","btn btn-sm btn-primary");
					});
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;

					if(thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href = "login.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		var title=$('#title').val().trim();

		init(title,pageclickednumberm);
	}
	
		

	function deleteeach(id){
			if(confirm("您确定要删除这类目吗？")){
				$.ajax({
					url: urlcore + "/api/classify/deleteOne?id="+id,
					type: "get",
					dataType: 'json',
					contentType: "application/json;charset=utf-8",
					success:function(data){
					     window.location="classify_list.html"
					},
					error:function() {
						/* Act on the event */
						alert("error");
					}
				});	
			}
	}
/**
		 * 搜索
		 */
		function searchList(){
			var title=$('#title').val();
			init(title,1);
		}



function findMyCatalogue(){
	$.ajax({
		url: urlcore + "/api/roleThirdCatalogue/findAllByUser?secondTitle="+jName,
		type: "GET",
		dataType: 'json',
		async: false,
		contentType: "application/json;charset=utf-8",
		success:function(data){
		if (data.success == true) {
			$.each(data.data, function(i,n) {
				arrayTitle.push(n.thirdCatalogue.title);
			});
		} else {
			alert(data.msg);
		}

		},
		error:function() {
			alert("error");
		}
	});
}